package com.huangyi;

public class Main {
    public static void main(String[] args) {
        //长度最小的子数组
        class Solution {
            public int minSubArrayLen(int target, int[] nums) {
                int min_len=Integer.MAX_VALUE,n=nums.length,sum =0;
                for(int left =0,right=0;right<n;right++){
                    sum += nums[right];
                    while(sum >= target){
                        int length = right-left+1;
                        min_len = Math.min(min_len,length);
                        sum-=nums[left++];
                    }
                }
                return min_len == Integer.MAX_VALUE ?0:min_len;
            }
        }


        //无重复字符的最长子串
        class Solution2 {
            public int lengthOfLongestSubstring(String ss) {
                int n = ss.length(),ret = 0;
                int[] hash = new int[128];
                char[] s = ss.toCharArray();
                for(int left = 0,right =0;right<n;right++){
                    hash[s[right]]++;
                    while(hash[s[right]]>1){
                        hash[s[left++]]--;
                    }
                    ret = Math.max(ret,right-left+1);


                }
                return ret;

            }
        }
    }
}